<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-menu"></i>{{$route.name}}
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div>
            <div class="handle-box">
                <el-date-picker v-model="searchTime" value-format="yyyy-MM-dd" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
                <el-button type="primary" @click="search">查询</el-button>
                <el-button type="primary" @click="exportExcel">导出
                    <i class="el-icon-download"></i>
                </el-button>
            </div>
            <div>
                <el-table :data="stay" border fit show-summary>
                    <el-table-column prop="createTime" label="时间" align="center">
                    </el-table-column>
                    <el-table-column prop="homeAd1Time" label="首页广告1" align="center">
                    </el-table-column>
                    <el-table-column prop="homeAd2Time" label="首页广告2" align="center">
                    </el-table-column>
                    <el-table-column prop="moviesTime" label="影视" align="center">
                    </el-table-column>
                    <el-table-column prop="gameTime" label="电玩" align="center">
                    </el-table-column>
                    <el-table-column prop="musicTime" label="音乐" align="center">
                    </el-table-column>
                    <el-table-column prop="bookTime" label="书吧" align="center">
                    </el-table-column>
                    <el-table-column prop="foodTime" label="点餐" align="center">
                    </el-table-column>
                    <el-table-column prop="cityTime" label="城市" align="center">
                    </el-table-column>
                    <el-table-column prop="subwayTime" label="城铁风采" align="center">
                    </el-table-column>
                    <el-table-column prop="staySum" label="总计" align="center">
                    </el-table-column>
                </el-table>
            </div>
            <div class="block">
                <el-pagination @current-change="handleCurrentChange" :current-page="num" layout="total,  prev, pager, next, jumper" :total="totalElements">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
import { getStay, exportModule } from '../../api/server.js'
import { ip } from '../../utils/local.js'
export default {
    data() {
        return {
            searchTime: '',
            stay: [],
            num: 1,
            totalElements: 10,
            ip: ip
        }
    },
    created() {
        this.getStays(1)
    },
    methods: {
        handleCurrentChange(val) {
            this.getStays(val)
        },
        search() {
            this.getStays(1)
        },
        getStays(index) {
            let time = this.searchTime
            let start, end
            if (time.length) {
                start = time[0]
                end = time[1]
            }
            getStay({ start, end, index })
                .then(res => {
                    this.stay = res.result
                    this.totalElements = res.resultNum
                })

        },
        exportExcel() {
            let time = this.searchTime
            let start, end
            if (time.length) {
                start = time[0]
                end = time[1]
            }
            let type = 0
            exportModule({ start, end, type })
                .then(res => {
                    window.open(ip + res.result, '_blank')
                })
        }
    }
}
</script>
<style lang="scss" scoped>
.handle-box {
  margin-bottom: 1%;
  .search {
    width: 30%;
  }
}

.block {
  text-align: center;
  margin-top: 1%;
}
</style>